<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>参赛车队</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="css/plugins/morris.css" rel="stylesheet">
	<link href="dist/css/bootstrapValidator.css" rel="stylesheet">
    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_evmq6xwfabutyb9.css"/>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/plug-ins/28e7751dbec/integration/bootstrap/3/dataTables.bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_i0327076nave7b9.css"/>
    <link href="nuget/content/content/toastr.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="css/datatable.css"/>
    <style>
		#example_paginate{
			float:right;
		}
		.handle-btn{
			cursor: pointer;
		    margin: 0 2px;
		}
		#wrapper {
		    padding-left:0px;
		}
		.navigation{
			border-bottom: 3px solid #edebeb;
		}
		
		.navigation a:hover{
			color: #0F6AFC;
			border-bottom: 2px solid #01AAED;
		}
		.this{
			color: #01aaed;
			font-weight:bold;
			border-bottom: 2px solid #01AAED;
		}
		#check>tbody>tr{
			line-height: 20px;
		}
		.odd{
			background: #f5f5f5;
		}
		[v-cloak] {
			display: none;
		}
		
		.control-label{
			color: #55d0c8;
		}
		.form-control{
			border-radius: 15px;
		}
	</style>
</head>

<body>
    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <a class="navbar-brand" href="index.html">无人车管理系统</a>
            </div>
            <!-- Top Menu Items -->
            <ul class="nav navbar-right top-nav">
                  
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> 用户名 <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="refereePwd.html"><i class="fa fa-fw fa-gear"></i> 修改密码</a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="login.html"><i class="fa fa-fw fa-power-off"></i> 退出</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">
           		<div class="row sss" >
					<nav class="navbar navbar-default" role="navigation">
						<div>
							<ul class="nav navbar-nav">
								<li>
									<a href="#" class="dropdown-toggle" data-toggle="dropdown">
										比赛信息
										<b class="caret"></b>
									</a>
									<ul class="dropdown-menu">
										<li><a href="index.html">比赛实况</a></li>
										<li class="divider">
										<li><a href="Check.html">比赛回查</a></li>
									</ul>
								</li>
								<li><a href="achievement.html">成绩管理</a></li>
								<li class="active"><a href="ParticipatingTeams.html">参赛车队</a></li>
								<li><a href="Court.html">赛场维护</a></li>
								<li><a href="Fault.html">场景维护</a></li>
								<li class="dropdown">
									<a href="#" class="dropdown-toggle" data-toggle="dropdown">
										基础数据
										<b class="caret"></b>
									</a>
									<ul class="dropdown-menu">
										<li><a href="device.html">设备管理</a></li>
										<li class="divider">
										<li><a href="Referee.html">裁判管理</a></li>
									</ul>
								</li>
							</ul>
						</div>
					</nav>
				</div>
                <div class="row">
                        <div class="panel-heading">
                        	<ul class="nav">
                        		<li style="float: left;">
                        			<b class="panel-title" style=" line-height: 34px;"><span style="padding-bottom: 5px; border-bottom: 3px solid #0aa788;">参赛</span>车队</b>
                        		</li>
                        		<li style="float: left; padding-left: 20px;">
									<button class="btn btn-primary" type="button" data-toggle="modal" data-target="#deviceStateModal">
							    		添加车队
									</button>
                        		</li>
                        	</ul>
                        </div>
                        <div class="panel">
	                        <div class="panel-body">
	                            <table id="example" class="display" width="100%"></table>
	                        </div>
                        </div>
                </div>
                <!-- 新增车队 -->
				<div class="modal fade" id="deviceStateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content" style="border-top: 5px solid #12dbcd;">
							<div class="modal-body">
		                        <div class="panel-body">
		                           <form class="form-horizontal" id="TeamsForm" method="get">
		                           	  <div class="text-center" style="line-height: 34px; margin-bottom: 5px; font-size: 16px;"><b>添加车队</b></div>
		                              <div class="form-group">
		                                  <label class="col-sm-2 control-label">车队名称</label>
		                                  <div class="col-sm-10">
		                                      <input type="text" name="teamName" id="teamName" class="form-control ">
		                                  </div>
		                              </div>
		                              <div class="form-group">
		                                  <label class="col-sm-2 control-label">参赛单位</label>
		                                  <div class="col-sm-10">
		                                      <input type="text" name="teamLeader"  class="form-control">
		                                  </div>
		                              </div>
		                              <div class="form-group">
		                                  <label class="col-sm-2 control-label">联系人</label>
		                                  <div class="col-sm-10">
		                                      <input type="text" name="teamOrganization"  class="form-control">
		                                  </div>
		                              </div>
		                              <div class="form-group">
		                                  <label class="col-sm-2 control-label">联系方式</label>
		                                  <div class="col-sm-10">
		                                      <input type="text" name="teamPhone"  class="form-control">
		                                  </div>
		                              </div>
		                                <div class="text-center">
		                                	<button type="button" class="btn " data-dismiss="modal" aria-hidden="true">
												关闭
											</button>
											<button type="submit" class="btn btn-primary" style="margin-left: 10px;">
												保存
											</button>
										</div>
		                            </form>
		                        </div>
							</div>
						</div><!-- /.modal-content -->
					</div><!-- /.modal -->
				</div>
                <!-- 修改车队 -->
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content"  style="border-top: 5px solid #12dbcd;">
							<div class="modal-body">
								<section class="panel">
			                        <div class="panel-body">
			                            <form class="form-horizontal" id="teamform" method="get">
			                            	  <div class="text-center" style="line-height: 34px; margin-bottom: 5px; font-size: 16px;"><b>编辑车队</b></div>
				                              <div class="form-group">
				                              	  <input  name="teamId" type="hidden" :value="teamsObj.teamId"/>
				                                  <label class="col-sm-2 control-label">车队名称</label>
				                                  <div class="col-sm-10">
				                                      <input type="text" name="teamName"  class="form-control" :value="teamsObj.teamName">
				                                  </div>
				                              </div>
				                              <div class="form-group">
				                                  <label class="col-sm-2 control-label">参赛单位</label>
				                                  <div class="col-sm-10">
				                                      <input type="text" name="teamOrganization" :value="teamsObj.teamOrganization" class="form-control">
				                                  </div>
				                              </div>
				                                <div class="form-group">
				                                  <label class="col-sm-2 control-label">联系人</label>
				                                  <div class="col-sm-10">
				                                      <input type="text" name="teamLeader" :value="teamsObj.teamLeader" class="form-control">
				                                  </div>
				                                </div>
				                                <div class="form-group">
				                                  <label class="col-sm-2 control-label">联系方式</label>
				                                  <div class="col-sm-10">
				                                      <input type="text" name="teamPhone" :value="teamsObj.teamPhone" class="form-control">
				                                  </div>
				                                </div>
				                                <div class="text-center">
				                                	<button type="button" class="btn " data-dismiss="modal" aria-hidden="true">
														关闭
													</button>
													<button type="submit" class="btn btn-primary" style="margin-left: 10px;">
														保存
													</button>
												</div>
			                        	</form>
			                        </div>
			                    </section>
							</div>
							
						</div><!-- /.modal-content -->
					</div><!-- /.modal -->
				</div>
                <!-- /.删除 -->
                <div class="modal fade" id="Delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				    <div class="modal-dialog">
				        <div class="modal-content" style="border-top: 5px solid #12dbcd;">
				            <div class="modal-body text-center">确定要删除此项？</div>
				            <div class="text-center" style="padding-bottom: 15px;">
				                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				                <button style="margin-left: 10px;" type="button" v-on:click="Delete()" class="btn btn-primary">确定</button>
				            </div>
				        </div><!-- /.modal-content -->
				    </div><!-- /.modal -->
				</div>
            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
    <!-- tab table-->
	<script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
	<script src="http://cdn.datatables.net/plug-ins/28e7751dbec/integration/bootstrap/3/dataTables.bootstrap.js"></script>
	<script src="nuget/content/scripts/toastr.js"></script>
    <script type="text/javascript" src="js/common.js" ></script>
    <script type="text/javascript" src="dist/js/bootstrapValidator.min.js"></script>
    <!-- Morris Charts JavaScript -->
    <script src="js/plugins/morris/raphael.min.js"></script>
    <script type="text/javascript" src="js/vue/vue.js" ></script>
    <script type="text/javascript" src="js/vue/vue-router.js" ></script>
	<script>
		Vue.filter("timeChange", function(value) {
			return replaceTime(value / 1000);
		});
		var vue = new Vue({
		  el: '#wrapper',
		  data:{ 
		  	teamsObj: {
		  		deviceType : "",
		  		deviceName : "",
		  		deviceMode : "",
		  		deviceVersion : "",
		  		channel : "",
		  		ipAddress : "",
		  		servicePort : "",
		  		deviceRunState : "",
		  		sinceId : "",
		  		deviceAddress : "",
		  		deviceId: "",
		  		teamId:"",
		  	},
		  	Validator:{
				message:'This value is not valid',
					// 定义未通过验证的状态图标
			    feedbackIcons: {
				    valid: 'glyphicon glyphicon-ok',
				    invalid: 'glyphicon glyphicon-remove',
				    validating: 'glyphicon glyphicon-refresh'
			    },
			    fields:{
			   	
				    teamName:{
				     message:'车队名称非法',
				     validators:{
				      notEmpty:{
				       message:'车队名不能为空'
				      },
				      stringLength:{
				       min:3,
				       max:20,
				       message:'车队名称长度必须位于3到20之间'
				      },
				      
				     }
				    },
			    
				    teamLeader:{
				     message:'参赛单位非法',
				     validators:{
				      notEmpty:{
				       message:'参赛单位不能为空'
				      },
				      stringLength:{
				       min:3,
				       max:20,
				       message:'参赛单位长度必须位于3到20之间'
				      },
				     }
				    },
			    
				    teamOrganization:{
				     message:'联系人非法',
				     validators:{
				      notEmpty:{
				       message:'联系人不能为空'
				      },
				      stringLength:{
				       min:3,
				       max:20,
				       message:'联系人长度必须位于3到20之间'
				      },
				     }
				    },
					//电子邮箱
				    email:{
				     validators:{
				      notEmpty:{
				       message:'邮箱地址不能为空'
				      },
				      emailAddress:{
				       message:'请输入正确的邮箱地址'
				      }
				     }
				    },
			 
					//手机号码
				    teamPhone:{
				     validators:{
				      notEmpty:{
				       message:'手机号码不能为空'
				      },
				      stringlength:{
				       min:11,
				       max:11,
				       message:'请输入11位手机号码'
				      },
				      regexp:{
				       regexp:/^1[3|5|8]{1}[0-9]{9}$/,
				       message:'请输入正确的手机号码'
				      }
				     }
				    },
			
			   }
			},
		  },
		  mounted:function(){
		  	this.deviceBasicId();
		  	this.form();
		  },
		  methods:{
		  	form:function(){
				//车队新增
				$("#TeamsForm").bootstrapValidator(
					this.Validator
				).on("success.form.bv",function(){
					vue.deviceState();
				});
				//修改
				$("#teamform").bootstrapValidator(
					this.Validator
				).on("success.form.bv",function(){
					vue.Submit();
				});
		  	},
		  	
		  	//初始化显示详情
		  	deviceBasicId:function(){
		  		$(document).ready(function() {
				  var myTable = $('#example').DataTable({
				      "processing": false, //DataTables载入数据时，是否显示‘进度’提示  
				      "stateSave": true, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态  
				      "scrollCollapse": true, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变  
				      "paginationType": "full_numbers", //详细分页组，可以支持直接跳转到某页  
				      "language": lang, //提示信息
				      "destroy":true,//Cannot reinitialise DataTable,解决重新加载表格内容问题  
				      "autoWidth": true, //自适应宽度，
				      "lengthMenu": [8, 30, 50],
				      "stripeClasses": ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
				      "showRowNumber":true,
				      "searching": false, //是否允许Datatables开启本地搜索
				      "paging": false, //是否开启本地分页
				      "lengthChange": false, //是否允许产品改变表格每页显示的记录数
				      "info": false, //控制是否显示表格左下角的信息
				      //跟数组下标一样，第一列从0开始，这里表格初始化时，第四列默认降序
				      "ordering": false,
				      "deferRender": true, //延迟渲染
				      //"ajax":"json/device.json",
				      "ajax": {
				      	url : url +'/users/'+adminId+'/teams',
						type : 'get',
						data:{
							"currentPage":1,
							"pageSize":9999,
						},
						dataType : 'json',
						beforeSend: function(request) {
				            request.setRequestHeader("accessToken", accessToken);
				        },
						success : function(data) {
							if(data['code'] == 1){
								if(data.result.length != 0)
									$('#example').dataTable().fnAddData(data.result);
								else
									$('#example').dataTable().fnClearTable();
							}else{
								ifajax(data);
							}
						}
				      }, //数据的路径 "http://192.168.5.133:8081/ic-iot/admin/'+adminId+'/devices" /"json/device.json"
				     
				      "columns": [{
				        "data": function(obj){
				        	//var sceneId = getOption("sceneId",obj.sceneId);
				        	return '<a href="TeamDetails.html?teamId=' + obj.teamId + '" target="_blank" style="color:#1aa79d; text-decoration:none;"><b>' + obj.teamName + '</b></a>';
				        	
				        },
				        "sTitle": "车队", //标题
				        "sDefaultContent": "", //此列默认值为""，以防数据中没有此值，DataTables加载数据的时候报错  
				      }, {
				      	"data":"teamOrganization",
				      	"sTitle":"参赛单位",
				      	"sDefaultContent": "", 
				      },{
				      	"data":"teamLeader",
				      	"sTitle":"联系人",
				      	"sDefaultContent": "", 
				      }, {
				      	"data":"teamPhone",
				      	"sTitle":"联系电话",
				      	"sDefaultContent": "", 
				      },{
				      	"data": function(obj){
				        	var teamId = obj.teamId;
				            return '<span  title="编辑" class="handle-btn handle-btn-edit"  data-toggle="modal" data-target="#myModal" onclick=javascript:vue.team('+teamId+');><b class="iconfont icon-xiangqing" style="color:#ffbe00"></b></span><span  title="删除" data-toggle="modal" data-target="#Delete" onclick=javascript:vue.team('+teamId+'); class="handle-btn handle-btn-edit"><b class="iconfont icon-shanchu" style="color:#ffbe00"></b></span>';
				        },
				        "className": "td-handle",//data-user='+teid+'  id="test'+teid+'" 
				        "sTitle": "操作", //标题
				        "sDefaultContent": "", //此列默认值为""，以防数据中没有此值，DataTables加载数据的时候报错  onclick=javascript:team('+teamId+');
				      }],
				    });
				});
		  	},
		  	
		  	team : function(teamId){
		  		var _self=this;
			  	$.ajax({
		  			type: "get",
		  			url:url+'/users/'+adminId+'/teams/'+teamId,
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						_self.teamsObj = {}; 
						var result = data.result;
						_self.teamsObj = result;
					}
		  		});
			},
		  	//点击修改车队信息
		  	Submit:function(){
		  		var datas = formToJson($("#teamform"));
		  		var th = this;
		  		$.ajax({
		  			type: "PUT",
		  			url:url+'/users/'+adminId+'/teams',//http://60.205.229.131:8085/mark
		  			data:datas,
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						$('#myModal').modal('hide');
						th.deviceBasicId();//刷新
					}
		  		});
		  	},
		  	//新增
		  	deviceState:function(){
		  		var datas = formToJson($("#TeamsForm"));
		  		var th = this;
		  		$.ajax({
		  			type: "POST",
		  			url:url+'/users/'+adminId+'/teams',
		  			data:datas,
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						$('#deviceStateModal').modal('hide');
						th.deviceBasicId();//刷新
					}
		  		});
		  	},
		  	
		  	//删除
		  	Delete :function(){
		  		var teamId = $("#teamId").val();
	  			var th = this;
	  			$.ajax({
		  			type: "DELETE",
		  			url:url+'/users/'+adminId+'/teams/'+teamId, 
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						$('#Delete').modal('hide');
						th.deviceBasicId();//刷新
					}
		  		});
		  	},
		  },
		});

	</script>
</body>

</html>
